using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Global;
using CE.User;

public partial class Provider_UserMessage : System.Web.UI.Page
{
    protected string _header;
    protected string _body;
    protected string _footer;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["errorcode"] != null)
            {
                string _errcode = Request.Params["errorcode"].ToString();

                GetMessage(_errcode);
                lblMessageHeader.Text = _header;
                lblMessageBody.Text = _body;
                lblMessageFooter.Text = _footer;
            }
            
            if (Request.Params["mt"] != null && Request.Params["ec"] != null)
            {
                string _messagetype = Request.Params["mt"].ToString();
                Int32 _errcode = Convert.ToInt32(Request.Params["ec"].ToString());

                GetMessage(300, _messagetype, _errcode);
                lblMessageHeader.Text = _header;
                lblMessageBody.Text = _body;
                lblMessageFooter.Text = _footer;
            }
            else
            {
                lblMessageHeader.Text = "CompareXpress";
                lblMessageBody.Text = "No message found!";
                lblMessageFooter.Text = "Please <a href = 'ProviderHome.aspx'><b>click here</b></a> to <b> Home page</b>.!";
            }
        }
    }

    private void GetMessage(Int32 UserTypeId, string MessageType, Int32 ErrorCode)
    {
        MessageDB _messagedb = new MessageDB();
        DataTable _Message = new DataTable();
        _Message = _messagedb.GetMessage(UserTypeId, MessageType, ErrorCode);
        if (_Message != null && _Message.Rows.Count > 0)
        {
            _header = _Message.Rows[0]["Header"].ToString();
            _body = _Message.Rows[0]["Body"].ToString();
            _footer = _Message.Rows[0]["Footer"].ToString();
        }
        else
        {
            _header = "CompareXpress";
            _body = "No message found!";
            _footer = "Please <a href = 'ProviderHome.aspx'><b>click here</b></a> to <b> Home page</b>.!";
        }
    }

    private void GetMessage(string ErrorCode)
    {
        if (ErrorCode == "404")
        {
            _header = "Customer Membership Service";
            _body = "Invalid confirmation key.";
            _footer = "Please contact or request confirmation key.";
        }
        else if (ErrorCode == "100")
        {
            _header = "ComparExpress Membership Service";
            _body = "Thank you very much for choosing our service.";
            _footer = "Please check your registered email account to activate and confirm your account registration.";
        }
        else if (ErrorCode == "200")
        {
            _header = "ComparExpress Membership Service";
            _body = "Your account have been activated. You are ready to use your account, now!";
            _footer = "Please <a href = '../Provider/ProviderSecureLogin.aspx'><b>click here</b></a> to start!";
        }
        else if (ErrorCode == "199")
        {
            _header = "ComparExpress Membership Service";
            _body = "Password recovery information has been sent to your email. Please check email inbox now.";
            _footer = "Please <a href = '../car-insurance/car-and-policy-details.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            ClearAllSession();
        }
        else if (ErrorCode == "1991")
        {
            _header = "ComparExpress Membership Service";
            _body = "New Password has been changed.";
            _footer = "Please <a href = '../Provider/ProviderSecureLogin.aspx'><b>click here</b></a> to <b>Sign In</b>";
            //ClearAllSession();
        }
        else if (ErrorCode == "1992")
        {
            _header = "ComparExpress Membership Service";
            _body = "New Password has been reset.";
            _footer = "Please <a href = '../Provider/ProviderSecureLogin.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            ClearAllSession();
        }
        else if (ErrorCode == "1993")
        {
            _header = "ComparExpress Membership Service";
            _body = "Please try again later. Your session has been locked!";
            _footer = "Please <a href = '../Provider/ProviderSecureLogin.aspx'><b>click here</b></a> or <b>Sign In</b>";
            ClearOtherSession();
        }
        else if (ErrorCode == "1994")
        {
            _header = "ComparExpress Membership Service";
            _body = "You didn't change your password last two months ago. Please change your password now.";
            _footer = "Please <a href = '../Provider/ChangePassword.aspx'><b>click here</b></a> to <b>Change your password.</b>";
            ClearOtherSession();
        }
        else if (ErrorCode == "2000") // Provider Messages
        {
            _header = "ComparExpress Provider Service";
            _body = "Please contact your admin. Your account do not have the access for this page!";
            _footer = "Please <a href = '../Provider/ProviderHome.aspx'><b>click here</b></a> to Home Page";
       }
    }

    private void ClearAllSession()
    {
        Session[General.UserId] = null;
        Session[General.UserEmail] = null;
        Session[General.StartTime] = null;
        Session[General.RequestUrl] = null;
        Session[General.UserName] = null;

        Session[General.ProviderCompanyId] = null;
        Session.Abandon();
    }

    private void ClearOtherSession()
    {
    }
    
}
